package com.d1711.zhanggm.springboot.controller;


import com.d1711.zhanggm.springboot.entity.Area;
import com.d1711.zhanggm.springboot.entity.AreaVo;
import com.d1711.zhanggm.springboot.mapper.AreaMapper;
import com.d1711.zhanggm.springboot.service.IAreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 张国明
 * @since 2020-05-27
 */
@RestController
@RequestMapping("/area")
@CrossOrigin
public class AreaController {
    @Autowired
    private IAreaService iAreaService;

/*    @Autowired
    private AreaMapper areaMapper;*/

    /**
     * 查询所有的地区
     * 封装成树的关系subList
     * @return
     */
    @GetMapping("getListAll")
    public List<AreaVo> getListAll(){
        return iAreaService.getListAll();
//        return areaMapper.selectAllList(1);
    }

    /**
     * 根据pid查询城市列表
     * @param pid
     * @return
     */
    @GetMapping("getListByPid")
    public List<Area> getListByPid(Integer pid){
        Map<String,Object> queryMap = new HashMap<>();
        queryMap.put("pid",pid);
        return iAreaService.listByMap(queryMap);
    }
}
